<template>
	<view>
		<navbar title="日报" :autoBack="true"></navbar>
		<scroll-view scroll-y="true" class="scbox">
			<view class="con">
				<view class="con__box">
					<view class="con__box__a">
						<view class="con__box__t">
							汇报时间:当日10:00~次日10:00
						</view>
						<view class="con__box__ti">
							销售数据
						</view>
						<view class="u-flex u-flex-y-center">
							<view class="con__box__i">
								<view class="con__box__i__t">
									{{userinfo.username}}
								</view>
								<image src="/static/tool/fanhui.png" class="con__box__i__x" mode=""></image>
							</view>
							<view class="con__box__i">
								<view class="con__box__i__t">
									今天
								</view>
								<image src="/static/tool/fanhui.png" class="con__box__i__x" mode=""></image>
							</view>
						</view>
						<view class="con__box__time">
							时间:{{$u.timeFormat(new Date(), 'mm月dd日')}}
						</view>
						<view class="u-flex u-flex-y-center u-flex-wrap">
							<view class="con__box__numtime">
								<view class="con__box__numtime__num">
									{{info.createCustomer}}
								</view>
								<view class="con__box__numtime__text">
									入库客户数
								</view>
							</view>
							<view class="con__box__numtime">
								<view class="con__box__numtime__num">
									{{info.contractCustomer}}
								</view>
								<view class="con__box__numtime__text">
									联系客户数
								</view>
							</view>
							<view class="con__box__numtime">
								<view class="con__box__numtime__num">
									{{info.visitCustomer}}
								</view>
								<view class="con__box__numtime__text">
									拜访客户数
								</view>
							</view>
							<view class="con__box__numtime">
								<view class="con__box__numtime__num">
									{{info.successNum}}
								</view>
								<view class="con__box__numtime__text">
									成交订单量
								</view>
							</view>
							<view class="con__box__numtime">
								<view class="con__box__numtime__num">
									{{info.dedAmount}}
								</view>
								<view class="con__box__numtime__text">
									成交金额
								</view>
							</view>
							<view class="con__box__numtime">
								<view class="con__box__numtime__num">
									{{info.phoneCustomer}}
								</view>
								<view class="con__box__numtime__text">
									通话次数
								</view>
							</view>
						</view>

					</view>
					<u-gap height="22rpx" bgColor="#F8F8F8"></u-gap>
					<view class="con__box__b">
						<view class="con__box__title">
							<view class="con__box__title__line">

							</view>
							今日工作总结
						</view>
						<u--textarea :showConfirmBar='false' v-model="form.today" autoHeight placeholder="请输入..."
							border='none' :placeholderStyle='{color:"#919191",fontSzie:"24rpx",}'></u--textarea>
						<u-line color="#F8F8F8" margin='0 0 34rpx' :hairline='false'></u-line>
						<view class="con__box__title">
							<view class="con__box__title__line">

							</view>
							明日工作计划
						</view>
						<u--textarea :showConfirmBar='false' v-model="form.plan" autoHeight placeholder="请输入..."
							border='none' :placeholderStyle='{color:"#919191",fontSzie:"24rpx",}'></u--textarea>
						<u-line color="#F8F8F8" margin='0 0 34rpx' :hairline='false'></u-line>
						<view class="con__box__title u-flex-between">
							<view class="u-flex u-flex-y-center">
								<view class="con__box__title__line">

								</view>
								附件
							</view>
						</view>
						<view class=""
							style="color: #7A7A7A;font-size: 24rpx;line-height: 24rpx;margin: 40rpx 0 19rpx;">
							请上传
						</view>
						<view class="" style="margin: 35rpx 0 40rpx 0;">
							<u-upload :fileList="fileList6" @afterRead="afterRead" @delete="deletePic" name="6" multiple
								:maxCount="9" width="98rpx" height="98rpx">
								<image src="/static/tool/fj.png" mode="widthFix" style="width: 98rpx;height: 98rpx;">
								</image>
							</u-upload>
						</view>
						<view class="con__box__item">
							<view class="con__box__item__label">
								汇报给
							</view>
							<view class="con__box__item__inp u-flex u-flex-end u-flex-y-center"
								@click="navto('/pages/customer/checkxs')">
								<view class="con__box__item__inp__timelabel" v-if="!senduser.manager_name">
									请选择
								</view>
								<view class="con__box__item__inp__time" v-else>
									{{senduser.manager_name}}
								</view>
							</view>
							<image src="/static/homex/more2.png" class="con__box__item__m" mode="aspectFill"></image>
						</view>
						<view class="con__box__item" style="margin-bottom: 33rpx;">
							<view class="con__box__item__label">
								抄送给
							</view>
							<view class="con__box__item__inp u-flex u-flex-end u-flex-y-center"
								@click="navto('/pages/customer/checkxs?group_id=3')">
								<view class="con__box__item__inp__timelabel" v-if="!anduser.and_name">
									请选择
								</view>
								<view class="con__box__item__inp__time" v-else>
									{{anduser.and_name}}
								</view>
							</view>
							<image src="/static/homex/more2.png" class="con__box__item__m" mode="aspectFill"></image>
						</view>
						<u-button color="#3262FD" text="提交" @click="submit" :loading="loading"
							:customStyle='{width:"628rpx",height:"94rpx",margin:0,padding:0,borderRadius:"15rpx",fontSize:"32rpx"}'></u-button>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import sale from '@/api/_sale.js'
	export default {
		data() {
			return {
				value2: '',
				userinfo: uni.getStorageSync('dkuserinfo'),
				startTime: '',
				endtime: '',
				info: {},
				form: {
					today: '',
					plan: '',
					images: '',
					send_id: '',
					and_id: '',
					customer_total: 0,
					customer_contract: 0,
					customer_visit: 0,
					order: 0,
					order_amount: 0,
					call_count: 0,
					starttime: '',
					endtime: ''
				},
				fileList6: [],
				loading: false,
				senduser: {},
				anduser: {}
			};
		},
		methods: {
			async submit() {
				let img = []
				img = this.fileList6.map((item) => item.url.url)
				this.form.images = img.join(',')
				this.form.send_id = this.senduser.manager_id
				this.form.and_id = this.senduser.and_id
				this.form.starttime = this.startTime
				this.form.endtime = this.endtime
				this.form.customer_total = this.info.createCustomer
				this.form.customer_contract = this.info.contractCustomer
				this.form.customer_visit = this.info.visitCustomer
				this.form.call_count = this.info.phoneCustomer
				this.form.order = this.info.successNum
				this.form.order_amount = this.info.dedAmount
				let {
					today,
					plan,
					images,
					send_id,
					and_id
				} = this.form
				if (!today) {
					uni.$u.toast('请输入今日工作总结')
					return
				}
				if (!plan) {
					uni.$u.toast('请输入明日工作计划')
					return
				}
				if (!send_id) {
					uni.$u.toast('请选择汇报人')
					return
				}
				let _this = this
				this.loading = true
				let res = await sale.createDay(this.form)
				if (res.data.code == 1) {
					uni.$u.toast('提交成功')
					this.$store.commit('setanduser', null)
					this.$store.commit('setuser', null)
					setTimeout(() => {
						_this.loading = false
						uni.navigateBack()
					}, 1000)
				} else {
					_this.loading = false
				}
			},
			async getinfo() {
				let res = await sale.dayInfo({
					user_id: this.userinfo.id,
					startTime: this.startTime,
					endTime: this.endTime
				})
				if (res.data.code == 1) {
					this.info = res.data.data
				}
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1);
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file);
				let fileListLen = this[`fileList${event.name}`].length;
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: "uploading",
						message: "上传中",
					});
				});
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url);
					let item = this[`fileList${event.name}`][fileListLen];
					this[`fileList${event.name}`].splice(
						fileListLen,
						1,
						Object.assign(item, {
							status: "success",
							message: "",
							url: result,
						})
					);
					fileListLen++;
				}
			},
			uploadFilePromise(url) {
				let _this = this
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: "http://dn.fuliaoxx.com/api/common/upload", // 仅为示例，非真实的接口地址
						filePath: url,
						name: "file",
						formData: {
							user: "test",
						},
						success: (res) => {
							setTimeout(() => {
								resolve(JSON.parse(res.data).data);
							}, 1000);
						},
					});
				});
			},
		},
		onLoad() {
			let starttime = ''
			let endtime = ''
			let toData = new Date(new Date().toLocaleDateString()).getTime()
			starttime = uni.$u.timeFormat(toData, 'yyyy-mm-dd') + ' 00:00:00'
			endtime = uni.$u.timeFormat(toData, 'yyyy-mm-dd') + ' 23:59:59'
			this.startTime = new Date(starttime).getTime() / 1000
			this.endTime = new Date(endtime).getTime() / 1000
			this.getinfo()
		},
		onShow() {
			console.log(this.$store.state.curuser, this.$store.state.anduser)
			if (this.$store.state.curuser) {
				this.senduser = this.$store.state.curuser
			}
			if (this.$store.state.anduser) {
				this.anduser = this.$store.state.anduser
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f8f8f8;
	}

	.con {
		padding: 20rpx 30rpx 66rpx;

		&__box {
			// padding: 0 0 34rpx;
			background: #FFFFFF;
			border-radius: 20rpx;

			&__a {
				padding: 13rpx 0 0 33rpx;

			}

			&__b {
				padding: 33rpx 0 44rpx 30rpx;
			}

			&__t {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #83878A;
				line-height: 26rpx;
				padding: 37rpx 0;
				border-bottom: 2rpx solid #F9F9F9;
			}

			&__ti {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #010101;
				line-height: 30rpx;
				margin: 31rpx 4rpx 36rpx;
			}

			&__item {
				height: 104rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-right: 32rpx;
				border-bottom: 2rpx solid #F9F9F9;

				&__label {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #6D6D6D;
					line-height: 26rpx;
				}

				&__m {
					width: 12rpx;
					height: 21rpx;
					margin-left: 10rpx;
				}

				&__inp {
					flex: 1;
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #020202;
					line-height: 38rpx;
					text-align: right;

					.uni-input-placeholder {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #6D6D6D;
						line-height: 38rpx;
					}

					&__timelabel {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #6D6D6D;
						line-height: 38rpx;
					}
				}

				&__qhbox {
					width: 146rpx;
					height: 60rpx;
					background: #F8F8F8;
					border-radius: 8rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-left: 12rpx;

					&__i {
						width: 70rpx;
						height: 55rpx;
						background: #F8F8F8;
						border-radius: 8rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 24rpx;
						color: #010101;
						line-height: 24rpx;
					}

					.ac {
						background: #3262FD;
						color: #FFFFFF;
					}
				}
			}

			&__i {
				width: 303rpx;
				height: 73rpx;
				background: #F8F8F8;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-right: 20rpx;

				&__t {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #212123;
					line-height: 30rpx;
					margin-left: 25rpx;
				}

				&__x {
					width: 20rpx;
					height: 12rpx;
					margin-right: 20rpx;
				}
			}

			&__time {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #6D7172;
				line-height: 30rpx;
				margin-top: 23rpx;
				margin-bottom: 46rpx;
			}

			&__numtime {
				width: 31%;
				margin-bottom: 47rpx;

				&__num {
					font-family: PingFang SC;
					font-weight: 800;
					font-size: 42rpx;
					color: #000000;
					line-height: 32rpx;
					text-align: center;
					margin-bottom: 30rpx;

				}

				&__text {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #7A7A7A;
					line-height: 24rpx;
					text-align: center;
				}
			}

			&__title {
				display: flex;
				align-items: center;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #1E1E1E;
				line-height: 26rpx;
				margin-left: 7rpx;

				&__line {
					width: 6rpx;
					height: 24rpx;
					background: #3262FD;
					margin-right: 10rpx;
				}

				&__wh {
					width: 30rpx;
					height: 29rpx;
				}
			}

			&__up {
				width: 149rpx;
				height: 149rpx;
				margin-bottom: 40rpx;
				margin-top: 35rpx;
			}

			&__fj {
				width: 98rpx;
				height: 98rpx;
				margin: 0 0 58rpx;
			}
		}
	}

	::v-deep.u-textarea {
		padding: 30rpx 4rpx 68rpx;

		.u-textarea__field {
			font-size: 26rpx;
			color: #020202;
		}

		.uni-textarea-placeholder {
			color: #939393 !important;
			font-size: 26rpx;
		}
	}
</style>